package cn.edu.scau.cmi.yangjiamin.client;

import cn.edu.scau.cmi.yangjiamin.abstractfactory.AutoInsuranceFactory;
import cn.edu.scau.cmi.yangjiamin.abstractfactory.PICC;
import cn.edu.scau.cmi.yangjiamin.abstractfactory.PingAn;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;

public class AbstractFactoryGUI extends Application{
	@Override
	public void start(Stage primaryStage) throws Exception{
		BorderPane pane = new BorderPane();
		BorderPane paneCenter = new BorderPane();
		ImageView imageView = new ImageView(new Image("image/photo.jpg"));
	    paneCenter.setLeft(imageView);
	    VBox vbox = new VBox(15);
	    vbox.setPadding(new Insets(5,5,5,5));
		String s = "学号：201616030128  姓名：杨嘉敏";
		Text textPerson = new Text(100, 100, s);
		
		HBox hbox1 = new HBox(15);
		hbox1.setPadding(new Insets(5,5,5,5));
		Label label1 = new Label("请先选择公司");
		ComboBox<String> cbo1 = new ComboBox<>();
		cbo1.getItems().addAll("中国人寿保险", "平安保险");
		cbo1.setStyle("fx-color: red");
		hbox1.getChildren().addAll(label1, cbo1);
		
		HBox hbox2 = new HBox(15);
		hbox2.setPadding(new Insets(5,5,5,5));
		Label label2 = new Label("请选择保险类型");
		ComboBox<String> cbo2 = new ComboBox<>();
		cbo2.getItems().addAll("身体受伤", "汽车损坏", "人员伤亡", "多种事故");
		cbo2.setStyle("fx-color: red");
		hbox2.getChildren().addAll(label2, cbo2);
		
		
		Button show = new Button("显示保险信息");
		vbox.getChildren().addAll(textPerson, hbox1, hbox2, show);
		paneCenter.setCenter(vbox);
		pane.setTop(paneCenter);
		Text textInsurance = new Text(100,100, "显示保险的详细信息");
		pane.setCenter(textInsurance);
		cbo1.setOnAction(e->{
			String company = cbo1.getValue();//公司类型
			cbo2.setOnAction(e1->{
				String type =  cbo2.getValue();//保险类型
				show.setOnAction(e2->{
					AutoInsuranceFactory af = AutoInsuranceFactory.getAutoInsuranceFactory(type);
					String desc = "";
					if(company == "中国人寿保险") {
						PICC picc =  af.getPICC();
						desc = picc.getPICCInfo();
					}
					else if (company == "平安保险") {
						PingAn pingan = af.getPingAn();
						desc =  pingan.getPingAnInfo();
					}
					textInsurance.setText(desc);
				});
			});
		});
		
		Scene scene = new Scene(pane, 600, 500);
		primaryStage.setTitle("AbstractFactory");
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}

}
